package personal.service.accounting;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import personal.dao.accounting.AccountDAO;
import personal.domain.accounting.Account;
import personal.domain.accounting.AccountType;
import personal.domain.accounting.MonthendAccountBalance;
import personal.domain.accounting.MonthwiseCalendar;


@Service
public class AccountServiceImpl implements AccountService {
	private AccountDAO accountDAO;

	public AccountDAO getAccountDAO() {
		return accountDAO;
	}

	@Autowired(required=false)
	public void setAccountDAO(AccountDAO accountDAO) {
		this.accountDAO = accountDAO;
	}

	@Override
	@Transactional(readOnly=true)
	public List<Account> getAllAccounts() {
		return accountDAO.getAllAccounts();
	}

	@Override
	@Transactional(readOnly=true)
	public List<AccountType> getAllAccountTypes() {
		return accountDAO.getAllAccountTypes();
	}

	@Override
	@Transactional(readOnly=true)
	public List<MonthendAccountBalance> getMonthendAccountBalancesForYear(Long year) {
		MonthwiseCalendar calendar = new MonthwiseCalendar();
		calendar.setYear(year);
		return accountDAO.getCalendarMonthendAccountBalances(calendar);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRES_NEW)
	public Account saveAccount(Account account) {
		return accountDAO.saveAccount(account);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRES_NEW)
	public AccountType saveAccountType(AccountType accountType) {
		return accountDAO.saveAccountType(accountType);
	}

}
